package com.rhzy.wnhc.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.rhzy.wnhc.entity.TAuthCode;
import com.rhzy.wnhc.entity.TJobWish;
import com.rhzy.wnhc.service.TAuthCodeService;
import com.rhzy.wnhc.util.AjaxResult;
import com.rhzy.wnhc.util.CheckIdcardIsLegal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "小程序端接口-授权码认证")
@RestController
@RequestMapping("/code")
public class AuthCodeController {

    @Autowired
    TAuthCodeService authCodeService;
    @ApiOperation(value = "授权码认证", tags = {"小程序端接口-授权码认证",})
    @RequestMapping(value = "/auth/{code}", method = RequestMethod.GET)
    @Transactional
    public AjaxResult addWishJob(@PathVariable String code){
        try{

            if(StringUtils.isEmpty(code)){
                return AjaxResult.addError("授权码为空！");
            }
            TAuthCode authCode=authCodeService.getOne(new LambdaQueryWrapper<TAuthCode>().eq(TAuthCode::getAuthCode,code));
            String areainfo=authCode.getAreaInfo();
            int length=areainfo.length();
            String areaname=areainfo.substring(areainfo.lastIndexOf("/")+1,length);
            authCode.setAreaInfo(areaname);
            return AjaxResult.addSuccess(authCode);

        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.addError("异常："+e.getMessage());
        }
    }
}
